package com.team.service.impl;

import com.team.commons.dto.ActivityDto;
import com.team.commons.dto.JourneyDto;
import com.team.commons.dto.ProductDetailsGatherDto;
import com.team.commons.utils.ColaBeanUtils;
import com.team.commons.vo.*;
import com.team.mapper.ImageMapMapper;
import com.team.service.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductionEditorServiceImpl implements ProductionEditorService {

    @Resource
    ProductService productService;
    @Resource
    JourneyService journeyService;
    @Resource
    ActivityService activityService;
    @Resource
    ImageMapService imageMapService;

    @Override
    public ProductDetailsGatherDto selectProductionEditor(Long productId) {
        ProductDetailsVo productDetailsVo = productService.selectProductDetails(productId);
        JourneyVo journeyVo = journeyService.selectJourneyById(productId);
        List<ActivityVo> activityVos = activityService.selectListActivityById(journeyVo.getId());
        ProductDetailsGatherDto dto = new ProductDetailsGatherDto();
        List<ImageMapVo> imageMapVos = imageMapService.selectImageMap();

        dto.setProductDetailsVo(productDetailsVo);
        dto.setActivityVoList(activityVos);
        dto.setJourneyVo(journeyVo);
        dto.setImageMapVos(imageMapVos);
        return dto;
    }

    @Override
    public Integer updateProductionEditor(ProductDetailsGatherDto productDetailsGatherDto) {
        Integer integer=0;
        integer = productService.updateProduct(productDetailsGatherDto.getProductDetailsVo());
        JourneyDto journeyDto = new JourneyDto();
        ColaBeanUtils.copyProperties(productDetailsGatherDto.getJourneyVo(),journeyDto);
        integer = journeyService.updateJourney(journeyDto);
        List<ActivityVo> activityVoList = productDetailsGatherDto.getActivityVoList();
        List<ActivityDto> activityDtos = ColaBeanUtils.copyListProperties(activityVoList, ActivityDto::new);
        activityDtos.forEach(dos->{activityService.updateActivity(dos);});
        return integer;
    }
}
